<template>
    <div
        class="box-group-wrap baseInfostyle"
        v-loading="pageLoading"
        element-loading-background="rgba(255, 255, 255, 0.7)"
    >
        <p class="title">客户来电信息</p>
        <!-- <div class="line"></div> -->
        <div class="content">
            <el-row>
                <el-col :span="24">
                    <p id="callNumber">
                        来电号码:
                        <!--<span class="tel">18837123489</span>-->
                        <!-- <span class="tel"> {{ getAnis | handleGetAnis(currentSessionObj)}}</span> -->
                        <span class="tel">{{showDnisNum}}</span>
                    </p>
                </el-col>
                <el-col :span="13">
                    <p>
                        客户等级:
                        <span>{{custVip}}</span>
                    </p>
                </el-col>
                <el-col :span="11">
                    <p>
                        历史投诉客户:
                        <span>{{hisCustts}}</span>
                    </p>
                </el-col>
                <el-col :span="24">
                    <p>
                        来电地区:
                        <span>{{area}}</span>
                    </p>
                </el-col>
                <el-col :span="22">
                    <!--<p>-->
                    <!--姓名:-->
                    <!--<span>{{customerInfo_3002.CHINAME}}</span>-->
                    <!--</p>-->
                    <!--<p>-->
                    <!--证件类型:-->
                    <!--<span>{{customerInfo_3002.KEYTYPE|filterKetype}}</span>-->
                    <!--</p>-->
                    <!--<p>-->
                    <!--证件号:-->
                    <!--<span>{{customerInfo_3002.CUSTID}}</span>-->
                    <!--</p>-->
                    <!--<p>-->
                    <!--手机号:-->
                    <!--<span>{{customerInfo_3002.MOBILEPHONE}}</span>-->
                    <!--</p>-->
                    <!--<p>-->
                    <!--短信功能:-->
                    <!--<span>{{SMSYNValue}}</span>-->
                    <!--</p>-->
                    <!--<p>-->
                    <!--人民币扣款方式:-->
                    <!--<span>{{REPAYCODE_filter}}</span>-->
                    <!--</p>-->
                    <!--<p>-->
                    <!--自扣账号:-->
                    <!--<span>{{cardAccountInfo_3001.BANKACCT}}</span>-->
                    <!--</p>-->
                    <!-- <p>
                        账户信用历史:
                        <span>{{CUPAYM24_Value}}</span>
                    </p>-->
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex';
import moment from 'moment';
import { getDictMappingValue } from '@/utils/Common';
import { isEmptyObject } from '@/utils/Object';
import { PAPERS_TYPE } from '@/utils/Contants';
import request from '@/apis/request';

export default {
    name: 'baseInfo',
    data() {
        return {
            SMSYNValue: '', // 短信功能
            pageLoading: true,
            REPAYCODE_filter: '', // 人民币扣款方式
            // CUPAYM24_Value:'',
            // creditCard_3014:'',
            CARDTO_Value: '', // 3014
            // isCard3054:'',
            getAnis: '', // 来电号码
            area: '', // 来电地区
            custVip: '普通客户', // 客户等级
            hisCustts: '否', // 历史投诉客户
        };
    },
    // props: {
    //     baseInfos:{
    //       type:Object,
    //       required:true,
    //     },
    // },
    // 3074 查卡列表  通过卡列表


    filters: {
        isGender: (value) => {
            const val = (`${value}`).trim();
            if (val === 'M') {
                return '男';
            } if (val === 'F') {
                return '女';
            }
            return val;
        },
        filterData: (value) => {
            if (value) {
                return moment(`${value}`, 'YYYYMMDD').format('YYYY-MM-DD');
            }
            return '';
        },
        filterPinset: (value) => {
            value = (`${value}`).trim();
            if (value === '0') {
                return '未设置';
            } if (value === '1') {
                return '已设置';
            }
        },
        filterKetype: (value) => {
            value = (`${value}`).trim();
            for (let index = 0; index < PAPERS_TYPE.length; index++) {
                const element = PAPERS_TYPE[index];
                if (element.value === value) {
                    return element.name;
                }
            }
        },
        // 判断软电话数据是非为空
        handleGetAnis: (val, currentSessionObj) => {
            function isEmptyObject(target) {
                return Object.keys(target).length === 0;
            }
            if (isEmptyObject(currentSessionObj)) {
                return '无电话';
            } else {
                if (top.softphone.direction === 'in') { // 呼入
                    // $('#idleBtn').text();
                    return currentSessionObj.ani;
                } else if (top.softphone.direction === 'out') { // 外呼
                    return currentSessionObj.dnis;
                }
            }
        },
    },
    computed: {
        ...mapGetters([
            'defaultParams', // 默认请求报文
            'customerInfo_3002', // 客户信息 3002
            'cardAccountInfo_3001', // 3001按卡号查询卡账户资料信息
            'cardInfo_3004',
            'CreditCardService_3014',
            'CardBill_3005',
            'CreditCardHistory_3054',
            'currentSessionObj',
        ]),
        // 这块还需要3002

        defaultParam() {
            return this.defaultParams;
        },
        CUPAYM24_Value() {
            if (!isEmptyObject(this.CreditCardHistory_3054)) {
                return this.CreditCardHistory_3054.CUPAYM24;
            }
        },
        showDnisNum() {
            if (!isEmptyObject(this.currentSessionObj)) {
                if (top.softphone.direction === 'in') { // 呼入
                    // $('#idleBtn').text();
                    return this.currentSessionObj.ani;
                } else if (top.softphone.direction === 'out') { // 外呼
                    return this.currentSessionObj.dnis;
                }
            } else {
                return '无电话';
            }
        }
    },

    async mounted() {
        this.getstateFunc();
    },
    updated() {
        this.area = this.currentSessionObj.area;
    },
    watch: {
        customerInfo_3002(newValue, oldValue) {
            if (newValue.CUSTID !== oldValue.CUSTID) {
                this.getHisCustts();
            }
        },
    },
    methods: {
        //  执行 异步
        async getstateFunc() {
            await this.getasyncFun();
            this.pageLoading = false;
        },
        // 异步查询字段值
        async getasyncFun() {
            this.SMSYNValue = await getDictMappingValue('SMSYN', this.cardAccountInfo_3001.SMSYN, this);
            if (!isEmptyObject(this.cardAccountInfo_3001)) {
                this.REPAYCODE_filter = await getDictMappingValue('REPAYCODE', this.cardAccountInfo_3001.REPAYCODE, this);
            }
            let stmdc_value = await getDictMappingValue('STMCD', this.CreditCardService_3014.STMCODE, this);
            stmdc_value = (`${stmdc_value}`).trim();
            if (!stmdc_value) {
                this.CARDTO_Value = '无任何账单寄送方式';
            } else {
                this.CARDTO_Value = stmdc_value;
            }
        },
        getHisCustts() {
            if (this.cardInfo_3004.CUSTID != '' && this.cardInfo_3004.CUSTID != undefined) {
                const appBody = {
                    IdentNo: this.cardInfo_3004.CUSTID, // 证件类型
                    BgnDt: moment(new Date(new Date().getTime() - (1000 * 60 * 60 * 24 * 180))).format('YYYYMMDD'), // 起始日期
                    EndDt: moment(new Date()).format('YYYYMMDD'), //  结束日期

                };
                const params = JSON.parse(JSON.stringify(this.defaultParams));
                params.body.appHead.tranCode = '00001';
                params.body.appBody = appBody;
                // 跑 00001交易
                this.$post.common.esbtran(params).then((res) => {
                    this.pageLoading = false;
                    if (res.status === 200) { // 接口请求成功
                        const result = JSON.parse(res.data.jsonRes);
                        if (result.sysHead.rspCd === '000000') {
                            const list = result.body.appBody.array.WrkShdInf;
                            if (list.length > 0) {
                                this.hisCustts = '是';
                            } else {
                                this.hisCustts = '否';
                            }
                        }
                    }
                });
            }
        },

        // // 3054卡片信用历史查询（ACRED）
        // async getCardHistory3054(){
        //     let defaultParamInfos = JSON.parse(JSON.stringify(this.defaultParams));
        //     defaultParamInfos.body.appHead.tranCode = '3054';//修改交易号
        //     defaultParamInfos.body.appBody.PINFLAG='0';
        //     defaultParamInfos.body.appBody.PIN='';
        //     defaultParamInfos.body.appBody.CARDNO= this.cardInfo_3004.CARDNO;//卡号
        //     defaultParamInfos.body.appBody.CARDNBR=this.cardInfo_3004.CARDNO;//卡号
        //     defaultParamInfos.body.appBody.OPTION='L';//第一币种
        //     defaultParamInfos.body.appBody.QUERY='0'; //19-24月的信用历史
        //     await this.$post.common.transPort(defaultParamInfos).then( res=>{
        //         console.log(res);
        //         if(res.status === 200){ //请求成功
        //                 let cardlossofs = JSON.parse(res.data.jsonRes);
        //                 console.log(cardlossofs,'3054卡片信用历史');
        //                 if(cardlossofs.sysHead.rspCd =="000000"){ //交易成功 CUPAYM24
        //                 this.isCard3054= cardlossofs.body.appBody
        //                   this.CUPAYM24_Value = cardlossofs.body.appBody.CUPAYM24;
        //                 // 更新vuex 数据
        //                   this.$store.commit('common/UPDATE_CREDIT_CARD_HISTORY',cardlossofs.body.appBody);
        //                 }else{
        //                     // let ErrorMessage = '错误码：'+cardlossofs.sysHead.rspCd+' '+'错误信息：'+cardlossofs.sysHead.rspMsg;
        //                     // this.$alert(ErrorMessage, cardlossofs.sysHead.busiName, {
        //                     //     customClass: 'error'
        //                     // })
        //                 }
        //             }
        //     })
        // },
    },
};
</script>

<style  lang='scss' >
.baseInfostyle {
    .content p {
        font-size: 12px;
        color: #666;
        span {
            color: #333;
            font-weight: 800;
        }
    }
}
.businessSystem-left .box-group {
    padding: 10px;
    min-height: 116px;
}
</style>
